package com.shop.controller;

import com.shop.constant.MessageConstant;
import com.shop.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/managers")
@Api(tags = "管理员名称管理")
public class ManagerListController {
    //获得当前登录用户的用户名
    @GetMapping("/getManagername")
    @ApiOperation("显示管理员名称接口")
    public Result getUsername(){
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        System.out.println(user);
        if(user==null){
            return new Result(false,MessageConstant.QUERY_MANAGER_FAIL);
        }
        String name=user.getUsername();
        return new Result(true,MessageConstant.QUERY_MANAGER_SUCCESS,name);
    }
}
